/**
 * 
 * @author Alfredo Paz
 * Adaptado del material de Burroughes, Heijltjes, Walder para Haskell
 *
 */

#include <GL/glut.h>
#include "Picture.h"
#include "GPicture.h"

Picture *pic;

void reshape_cb (int w, int h) {
	if (w==0||h==0) return;
	glViewport(0,0,w,h);
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	gluOrtho2D(0,w,0,h);
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();
}

void display_cb() {
	glClear(GL_COLOR_BUFFER_BIT);
	GPicture gp(pic);
	gp.paint();
	
	glutSwapBuffers();
}

void initialize() {
	glutInitDisplayMode (GLUT_RGBA|GLUT_DOUBLE);
	glutInitWindowSize (pic->getWidth(),pic->getHeight());
	glutInitWindowPosition (100,100);
	glutCreateWindow ("Chess Screen");
	glutDisplayFunc (display_cb);
	glutReshapeFunc (reshape_cb);
	glClearColor(0.f,0.6f,1.0f,1.f);
}

int main (int argc, char **argv) {
	glutInit (&argc, argv);
        	//pic = Picture::casilleroBlanco()->superponer(Picture::alfil());
			//pic = Picture::casilleroBlanco()->superponer(Picture::caballo());

			//pic = Picture::casilleroBlanco()->superponer(Picture::caballo()->voltearH());
			pic = Picture::casilleroBlanco()->superponer(Picture::caballo())->alLado(Picture::alfil());
			//pic = Picture::casilleroBlanco()->superponer(Picture::caballo())->repetirH(4);
	initialize();
	glutMainLoop();
	return 0;
}
